package edu.stthomas.seis770.visitor;

import COM.hilbertinc.base.HException;


/**
 * Exercise part2 driver
 */
public class HTMLVisitorDriver {

    public static void main(java.lang.String[] args) {

        if (0 == args.length) {
            System.err.println("Syntax: edu.stthomas.seis770.visitor.HTMLVisitorDriver <xmldocument>");
            return;
        }

        try {
            System.out.println("<!-- Parsing... -->");

            HTMLDomParser parser = new HTMLDomParser();
            parser.parse(args[0]);
            if (null == parser.getDocument()) {
                System.out.println("Document was not successfully parsed");
                System.out.println("If there are no error messages, it is probably an inability to find the DTD");
                return;
            }

            System.out.println("<!-- Done.  Dumping contents of parsed document. -->");
            try {
                HTMLVisitor htmlVisitor = new HTMLVisitor();
                parser.traverse(htmlVisitor);
                htmlVisitor.flush();
                System.out.println("<!-- Done. -->");
            } catch (Exception exception) {
                throw new HException(exception, "Error dumping the contents of the document");
            }
        } catch (HException exception) {
            System.err.println("Exception...");
            exception.printStackTrace();
        }
    }
}